const Mock = require('mockjs')
const asyncRoutes = require('./routes.js')

const roles = [
  {
    key: 'admin',
    name: 'admin',
    description: '超级管理员,有权查看所有页面。',
    routes: asyncRoutes
  },
  {
    key: 'editor',
    name: 'editor',
    description: '普通编辑,可以看到接口文档以外的所有页面',
    routes: asyncRoutes
  }
]

module.exports = [
  // 获取所有路由表
  {
    url: '/routes',
    type: 'get',
    response: _ => {
      return {
        code: '0',
        data: asyncRoutes
      }
    }
  },

  // 获取所有角色
  {
    url: '/roles',
    type: 'get',
    response: _ => {
      return {
        code: '0',
        data: roles
      }
    }
  },

  // 添加角色
  {
    url: '/role',
    type: 'post',
    response: {
      code: '0',
      data: {
        key: Mock.mock('@integer(300, 5000)')
      }
    }
  },

  // 更新角色
  {
    url: '/role/[A-Za-z0-9]',
    type: 'put',
    response: {
      code: '0',
      data: {
        status: 'success'
      }
    }
  },

  // 删除角色
  {
    url: '/role/[A-Za-z0-9]',
    type: 'delete',
    response: {
      code: '0',
      data: {
        status: 'success'
      }
    }
  }
]
